﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using HtmlExtractor.XPathOutput;
namespace HtmlExtractor.XPathOutput
{
    /// <summary>
    /// 链必须存在一个处理，否则异常
    /// </summary>
    public class XPathOutputPathProcessorChain : List<XmlDocOutputPathProcessor>
    {   
        public static XPathOutputPathProcessorChain DefaultChain(IGrouping<List<string>, IPageItem> inputData)
        {
            XPathOutputPathProcessorChain chain = new XPathOutputPathProcessorChain();
            chain.Add(new OneOneCompositeProcessor(inputData));
            chain.Add(new OneOneSimpleProcessor(inputData));
            chain.Add(new OneManyCompositeProcessor(inputData));
            chain.Add(new OneManySimpleProcessor(inputData));
            return chain;
        }
        internal bool Process(ref XDocument data)
        {
            foreach (XmlDocOutputPathProcessor processor in this)
            {
                if (processor.GetResult(ref data))
                    return true;
            }
            throw new NotImplementedException();
        }
       
    }
}
